#include "comm.h"

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

static void work(void * request, void * ctx)
{
    printf("%d work\n", (int)(unsigned long)request);
    usleep(20 * 1000);
    printf("%d done\n", (int)(unsigned long)request);
}

int main(int argc, char * argv[])
{
    while(1) {
        thread_pool * pool = thread_pool_create(3, 0);
        int i = 0;
        for (i = 0; i < 100; i++) {
            if (thread_pool_do(pool, work, (void*)(unsigned long)i) == 0) {
                printf("thread_pool_do %d success\n", i);
            } else {
                fprintf(stderr, "thread_pool_do %d failed\n", i);
            }
            usleep(10 * 1000);
            //sleep(1);
        }

//        thread_pool_destory(pool);
        thread_pool_safe_exit();

        printf("done\n");
        if (getchar() == 'q') {
            break;
        }
    }
    return 0;
}
